from Products.Five.browser import BrowserView

class Progress(BrowserView):
    
    def getProgress(self):

        tasks = context.portal_catalog.searchResults(portal_type=('Task',), path={'query':'/'.join(project.getPhysicalPath()),}, sort_on='Date', sort_order='reverse',)

        taskDict = {}
        taskList = []
        estimated = 0
        used = 0
        
        if len(tasks) > 0:
        
          for task in tasks:
            taskList.append(task)
            if task.getEstimated_hours != None:
              estimated = estimated + task.getEstimated_hours
            if task.getUsed_hours != None:
              used = used + task.getUsed_hours
                    
          if used != 0 and estimated != 0:
              tmp_value = (used*100)/estimated
              if tmp_value <= 100:
                  projectProgress = tmp_value 
          else:
              projectProgress = 0
              
          return projectProgress
        
